"""
<name>Cox ZPH</name>
<author>Generated using Widget Maker written by Kyle R. Covington</author>
<RFunctions>survival:cox.zph</RFunctions>
<tags>Survival</tags>
<icon>survival.png</icon>
"""
from OWRpy import * 
import redRGUI, signals
class cox_zph(OWRpy): 
	def __init__(self, **kwargs):
		OWRpy.__init__(self, **kwargs)
		self.setRvariableNames(["cox.zph"])
		self.data = {}
		self.RFunctionParam_fit = ''
		self.inputs.addInput("fit", 'COX Model Fit', signals.survival.RCoxphFit, self.processfit)
		
		box = redRGUI.base.widgetBox(self.controlArea, orientation = 'horizontal')
		self.RFunctionParamglobal_lineEdit =  redRGUI.base.lineEdit(box, label = "global:")
		self.RFunctionParamtransform_lineEdit =  redRGUI.base.lineEdit(box, label = "transform:")
		redRGUI.base.commitButton(self.bottomAreaRight, "Commit", callback = self.commitFunction)
		self.RoutputWindow = redRGUI.base.textEdit(self.controlArea, label = "RoutputWindow")
	def processfit(self, data):
		if not self.require_librarys(["survival"]):
			self.status.setText('R Libraries Not Loaded.')
			return
		if data:
			self.RFunctionParam_fit=data.getData()
			#self.data = data
			self.commitFunction()
		else:
			self.RFunctionParam_fit=''
	def commitFunction(self):
		if str(self.RFunctionParam_fit) == '': return
		injection = []
		if str(self.RFunctionParamglobal_lineEdit.text()) != '':
			string = 'global='+str(self.RFunctionParamglobal_lineEdit.text())+''
			injection.append(string)
		if str(self.RFunctionParamtransform_lineEdit.text()) != '':
			string = 'transform='+str(self.RFunctionParamtransform_lineEdit.text())+''
			injection.append(string)
		inj = ','.join(injection)
		self.R(self.Rvariables['cox.zph']+'<-cox.zph(fit='+str(self.RFunctionParam_fit)+','+inj+')')
		self.R('txt<-capture.output('+self.Rvariables['cox.zph']+')')
		self.RoutputWindow.clear()
		tmp = self.R('paste(txt, collapse ="\n")')
		self.RoutputWindow.insertHtml('<br><pre>'+tmp+'</pre>')
